﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

using QuanLyChoVay.Entity;
using QuanLyChoVay.Database;

namespace QuanLyChoVay.Bussiness
{
   
    class KhachHangBuss
    {
        private DatabaseAccess da;

        public void insertKhachHang(KhachHang kh)
        {
            SqlParameter[] para = new SqlParameter[10];
            para[0] = new SqlParameter("@tendn",SqlDbType.VarChar,30);
            para[0].Value = kh.Tendn;
            para[1] = new SqlParameter("@matkhau", SqlDbType.VarChar, 30);
            para[1].Value = kh.Matkhau;
            para[2] = new SqlParameter("@hoten", SqlDbType.VarChar, 30);
            para[2].Value = kh.Hoten;
            para[3] = new SqlParameter("@email", SqlDbType.VarChar, 50);
            para[3].Value = kh.Email;
            para[4] = new SqlParameter("@diachi", SqlDbType.VarChar, 60);
            para[4].Value = kh.Diachi;
            para[5] = new SqlParameter("@ngaysinh", SqlDbType.Date);
            para[5].Value = kh.Ngaysinh;
            para[6] = new SqlParameter("@sdt", SqlDbType.VarChar, 11);
            para[6].Value = kh.Sdt;
            para[7] = new SqlParameter("@quequan", SqlDbType.VarChar, 60);
            para[7].Value = kh.Quequan;
            para[8] = new SqlParameter("@tienluong", SqlDbType.Int);
            para[8].Value = kh.Tienluong;
            para[9] = new SqlParameter("@tochuc", SqlDbType.VarChar, 50);
            para[9].Value = kh.Tochuc;

            da = new DatabaseAccess();
            da.ExecuteProc("KhachHang_insert",para);
        }

        public DataTable select_KhachHang_dangnhap(String tendn, String matkhau)
        {
            SqlParameter[] para = new SqlParameter[2];
            para[0] = new SqlParameter("@tendn", SqlDbType.VarChar, 30);
            para[0].Value = tendn;
            para[1] = new SqlParameter("@matkhau", SqlDbType.VarChar, 30);
            para[1].Value = matkhau;

            da = new DatabaseAccess();
            DataSet ds = new DataSet();
            ds = da.ExecuteProcSelect("KhachHang_selectdangnhap", para);
            DataTable dt = new DataTable();
            dt = ds.Tables[0];

            return dt;
        }
        public DataTable select_KhachHang_bytendn(string tendn)
        {
            SqlParameter[] para = new SqlParameter[1];
            para[0] = new SqlParameter("@tendn", SqlDbType.VarChar, 30);
            para[0].Value = tendn;

            da = new DatabaseAccess();
            DataSet ds = new DataSet();
            ds = da.ExecuteProcSelect("KhachHang_selectbytendn", para);
            DataTable dt = new DataTable();
            dt = ds.Tables[0];

            return dt;
        }
        public void update_KhachHang_bytendn(KhachHang kh)
        {
            SqlParameter[] para = new SqlParameter[10];
            para[0] = new SqlParameter("@tendn", SqlDbType.VarChar, 30);
            para[0].Value = kh.Tendn;
            para[1] = new SqlParameter("@matkhau", SqlDbType.VarChar, 30);
            para[1].Value = kh.Matkhau;
            para[2] = new SqlParameter("@hoten", SqlDbType.VarChar, 30);
            para[2].Value = kh.Hoten;
            para[3] = new SqlParameter("@email", SqlDbType.VarChar, 50);
            para[3].Value = kh.Email;
            para[4] = new SqlParameter("@diachi", SqlDbType.VarChar, 60);
            para[4].Value = kh.Diachi;
            para[5] = new SqlParameter("@ngaysinh", SqlDbType.Date);
            para[5].Value = kh.Ngaysinh;
            para[6] = new SqlParameter("@quequan", SqlDbType.VarChar, 60);
            para[6].Value = kh.Quequan;
            para[7] = new SqlParameter("@sdt", SqlDbType.VarChar, 11);
            para[7].Value = kh.Sdt;
            para[8] = new SqlParameter("@tienluong", SqlDbType.Int);
            para[8].Value = kh.Tienluong;
            para[9] = new SqlParameter("@tochuc", SqlDbType.VarChar, 50);
            para[9].Value = kh.Tochuc;

            da = new DatabaseAccess();
            da.ExecuteProc("KhachHang_updatebytendn",para);
        }
    }
}
